/*Copyright ©2015 TommyLemon(https://github.com/TommyLemon)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

package zblibrary.facechat.util;

import java.util.ArrayList;
import java.util.List;

import lingxi.entity.Feed;
import lingxi.entity.Like;
import zblibrary.facechat.viewmodel.impl.Discuss;
import zblibrary.facechat.modules.school.School;
import zblibrary.facechat.viewmodel.impl.ZUser;

/**仅测试用，图片地址可能会失效
 * @author Lemon
 */
public class TestUtil {

	public static List<ZUser> getUserList() {
		return getUserList(0);
	}
	/**
	 * @param page 页码
	 * @return
	 */
	public static List<ZUser> getUserList(int page) {
		return getUserList(page, 10);
	}
	/**
	 * @param page 页码
	 * @param count 最大一页数量
	 * @return
	 */
	public static List<Discuss> getDiscussList(int page, int count) {
		List<Discuss> list = new ArrayList<>();
		long userId;
		Discuss discuss;
		int length = (count <= 0 || count > URLS.length ? URLS.length : count);
		int index;
		for (int i = 0; i < length ; i++) {
			userId = i + page*length + 1;
			index = i + page*length;
			while (index >= URLS.length) {
				index -= URLS.length;
			}
			if (index < 0) {
				index = 0;
			}

			discuss = new Discuss();
			discuss.setId(userId);
			discuss.setPic(URLS[index]);
			discuss.setPrice(12.00F);
			discuss.setUser_id(10101010);
			discuss.setTitle("商品标题商品标题商品标题商品标题商");
			discuss.setPhone(String.valueOf(1311736568 + (i + userId)*(page + userId)));
			list.add(discuss);
		}
		return list;
	}

	public static List<Feed> getFeedList(int page, int count) {
		List<Feed> list = new ArrayList<>();
		long userId;
		Feed feed;
		int length = (count <= 0 || count > URLS.length ? URLS.length : count);
		int index;
		for (int i = 0; i < length ; i++) {
			feed = new Feed();
			feed.setFeedInfo("越长大你越会发现，你缺少的不是一个异性， 而是一个可以共鸣的灵魂。 #怎么突然就长大了呢# ");
			feed.setId("Idxxxx");
			List<Like> likeList = new ArrayList<>();
			for (int ii = 0; ii < 4; ii++) {
				Like like = new Like();
				like.setUsername("用户"+i);
				like.setUserId("123456");
				likeList.add(like);
			}
			feed.setLikeList(likeList);
			feed.setLike(true);
			feed.setCreateTime("2022-04-20");
			feed.setPhotoList(new ArrayList<String>(){{
				add(FeedURLs[0]);
				add(FeedURLs[1]);
				add(FeedURLs[2]);
				add(FeedURLs[3]);
				add(FeedURLs[4]);
				add(FeedURLs[5]);
			}});
			lingxi.entity.User user = new lingxi.entity.User();
			user.setAvatar(URLS[0]);
			user.setUsername("顾少秋");
			user.setId("test_id");
			feed.setUser(user);
			feed.setPosition(i);
			feed.setViewNum(i);
			list.add(feed);

			feed = new Feed();
			feed.setFeedInfo("车晓当着直播间20000多人的面，拿着两瓶雅诗兰黛眼霜说：平时一瓶400块钱，今天2瓶只要399元，一瓶也就199，多合适啊～");
			feed.setId("Idxxxx");
			likeList = new ArrayList<>();
			for (int ii = 0; ii < 4; ii++) {
				Like like = new Like();
				like.setUsername("用户"+i);
				like.setUserId("123456");
				likeList.add(like);
			}
			feed.setLikeList(likeList);
			feed.setLike(true);
			feed.setCreateTime("2022-04-20");
			feed.setPhotoList(new ArrayList<String>(){{
				add(FeedURLs[6]);
				add(FeedURLs[7]);
			}});
			user = new lingxi.entity.User();
			user.setAvatar(URLS[4]);
			user.setUsername("爱校园");
			user.setId("test_id");
			feed.setUser(user);
			feed.setPosition(i);
			feed.setViewNum(i);
			list.add(feed);
		}
		return list;
	}

	public static List<School> getSchoolList(int page, int count) {
		List<School> list = new ArrayList<>();
		long userId;
		School school;
		int length = (count <= 0 || count > URLS.length ? URLS.length : count);
		int index;
		for (int i = 0; i < length ; i++) {
			userId = i + page*length + 1;
			index = i + page*length;
			while (index >= URLS.length) {
				index -= URLS.length;
			}
			if (index < 0) {
				index = 0;
			}

			school = new School();
			school.setId(userId);
			school.setPic1(URLS[index]);
			school.setTitle("校园网通知");
			list.add(school);
		}
		return list;
	}


	public static List<ZUser> getUserList(int page, int count) {
		List<ZUser> list = new ArrayList<ZUser>();
		long userId;
		ZUser user;
		int length = (count <= 0 || count > URLS.length ? URLS.length : count);
		int index;
		for (int i = 0; i < length ; i++) {
			userId = i + page*length + 1;
			index = i + page*length;
			while (index >= URLS.length) {
				index -= URLS.length;
			}
			if (index < 0) {
				index = 0;
			}

			user = new ZUser();
			user.setId(userId);
			user.setSex(i%3);
			user.setHead(URLS[index]);
			user.setName("Name" + userId);
			user.setPhone(String.valueOf(1311736568 + (i + userId)*(page + userId)));
			user.setStarred(i%2 == 0);
			list.add(user);
		}
		return list;
	}

	/**
	 * 图片地址，仅供测试用
	 */
	public static String[] URLS = {
			"http://42.194.193.182:5000/images/goods/1.jpg",
			"http://42.194.193.182:5000/images/goods/2.jpg",
			"http://42.194.193.182:5000/images/goods/3.png",
			"http://42.194.193.182:5000/images/goods/4.png",
			"http://42.194.193.182:5000/images/goods/5.png",
			"http://42.194.193.182:5000/images/goods/6.jpg",
			"http://42.194.193.182:5000/images/goods/7.jpg",
			"http://42.194.193.182:5000/images/goods/8.jpg",
			"http://42.194.193.182:5000/images/goods/9.jpg",
			"http://42.194.193.182:5000/images/goods/10.jpg",
			"http://42.194.193.182:5000/images/goods/11.jpg",
			"http://42.194.193.182:5000/images/goods/12.jpg",
			"http://42.194.193.182:5000/images/goods/13.jpg",
			"http://42.194.193.182:5000/images/goods/14.jpg",
	};

	public static String[] goodsURL = {
			"http://42.194.193.182:5000/images/goods/WechatIMG16.jpeg",
			"http://42.194.193.182:5000/images/goods/WechatIMG17.jpeg",
			"http://42.194.193.182:5000/images/goods/WechatIMG18.jpeg",
			"http://42.194.193.182:5000/images/goods/WechatIMG19.jpeg",
			"http://42.194.193.182:5000/images/goods/WechatIMG20.jpeg",
	};

	public static String[] FeedURLs = {
			"http://42.194.193.182:5000/images/goods/WechatIMG22.jpeg",
			"http://42.194.193.182:5000/images/goods/WechatIMG23.jpeg",
			"http://42.194.193.182:5000/images/goods/WechatIMG24.jpeg",
			"http://42.194.193.182:5000/images/goods/WechatIMG25.jpeg",
			"http://42.194.193.182:5000/images/goods/WechatIMG26.jpeg",
			"http://42.194.193.182:5000/images/goods/WechatIMG27.jpeg",
			"http://42.194.193.182:5000/images/goods/WechatIMG29.jpeg",
			"http://42.194.193.182:5000/images/goods/WechatIMG30.jpeg",
	};

	public static String getPicture(int index) {
		return index < 0 || index >= URLS.length ? null : URLS[index];
	}

}
